package cn.tarena.ht.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.tarena.ht.mapper.UserInfoMapper;
import cn.tarena.ht.mapper.UserMapper;
import cn.tarena.ht.pojo.User;
@Service
public class UserServiceImpl implements UserService {
	@Autowired
	private UserMapper userMapper;
	@Autowired
	private UserInfoMapper userInfoMapper;

	public List<User> findAll() {
		return userMapper.findAll();
	}
	public void updateState(String[] userIds, int state) {
		userMapper.updateState(userIds,state);
	}
	public void deleteById(String[] userIds) {
		for (String userId : userIds) {
			userMapper.deleteUserRole(userId);
		}
		userInfoMapper.deleteById(userIds);
		userMapper.deleteById(userIds);
	}
	public void saveUser(User user) {
		userInfoMapper.saveUser(user);
		userMapper.saveUser(user);
	}
	public User findUserById(String userId) {
		return userMapper.findUserById(userId);
	}
	public void updateUser(User user) {
		userInfoMapper.updateUser(user);
		userMapper.updateUser(user);
	}
	public void saveUserRole(String userId, String[] roleIds) {
		userMapper.deleteUserRole(userId);
		for (String roleId : roleIds) {
			userMapper.saveUserRole(userId,roleId);
		}
	}
	public List<String> findUserRoleIdList(String userId) {
		return userMapper.findUserRoleIdList(userId);
	}
	public User findUserByUP(String userName, String password) {
		return userMapper.findUserByUP(userName,password);
	}
	public User findUserByUsername(String username) {
		return userMapper.findUserByUsername(username);
	}
	public List<String> findPrivilegeList(String userId) {
		return userMapper.findPrivilegeList(userId);
	}

}
